package com.ruoyi.web.controller.system;

import com.ruoyi.common.enums.HigherStatus;
import com.ruoyi.common.enums.TenantStatus;
import com.ruoyi.system.domain.SysBuildingVo;
import com.ruoyi.system.domain.SysHigher;
import com.ruoyi.system.domain.SysTenant;
import com.ruoyi.system.domain.SysUnit;
import com.ruoyi.system.service.ISysBuildingService;
import com.ruoyi.system.service.ISysHigherService;
import com.ruoyi.system.service.ISysTenantService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("/system/unitShow")
public class SysUnitShowController {

    private String prefix = "system/unitShow";

    @Autowired
    private ISysBuildingService sysBuildingService;

    @Autowired
    private ISysTenantService sysTenantService;

    @RequiresPermissions("system:unitShow:view")
    @GetMapping()
    public String unitShow(ModelMap mmap)
    {
        List<SysBuildingVo> list = sysBuildingService.unitShowlist(null);

        SysTenant sysTenant = new SysTenant();
        sysTenant.setRisePriceStatus(HigherStatus.WAIT.getCode());
        sysTenant.setTenantStatus(TenantStatus.LIVEING.getCode());
        List<SysTenant> tenantList = sysTenantService.selectSysTenantHigherList(sysTenant);

        for (SysBuildingVo sysBuildingVo : list) {
            for (SysUnit unit : sysBuildingVo.getUnits()) {
                for (SysTenant higher : tenantList) {
                    if (higher.getUnitNameStr().contains(unit.getUnitName())){
                        unit.setUnitStatus("3");
                    }
                }
            }
        }

        mmap.put("sysBuilding", list);
        return prefix + "/unitShow";
    }

}
